package com.enjoyor.health.HGPT.web.rest;

import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson2.JSONArray;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.enjoyor.health.HGPT.core.config.ParamConfig;
import com.enjoyor.health.HGPT.core.dto.ReservationWeekDto;
import com.enjoyor.health.HGPT.core.dto.ReservationWeekDtoV2;
import com.enjoyor.health.HGPT.core.entity.FileInfo;
import com.enjoyor.health.HGPT.core.entity.PhysicalExaminationPackage;
import com.enjoyor.health.HGPT.core.service.IPhysicalExaminationPackageService;
import com.enjoyor.health.HGPT.service.BizFileService;
import com.enjoyor.health.HGPT.service.BizReservationService;
import com.enjoyor.health.HGPT.web.CodeEnum;
import com.enjoyor.health.HGPT.web.RetResult;
import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.UUID;

/**
 * web页的登录接口
 * @author Zhu Min
 * @date 2023/11/1 11:43
 */
@Api(value = "登录页面", tags = {"Web页面管理接口"})
@CrossOrigin
@RequestMapping("/rest")
@RestController
public class WebLoginController {

    @Autowired
    private BizReservationService bizReservationService;
    @Autowired
    private IPhysicalExaminationPackageService physicalExaminationPackageService;
    @Autowired
    private ParamConfig paramConfig;
    @Autowired
    private BizFileService bizFileService;

    @ApiOperation(value = "登录")
    @PostMapping("/doLogin")
    public RetResult doLogin(String username, String password) {
        // 此处仅作模拟示例，真实项目需要从数据库中查询数据进行比对
        if(paramConfig.getUsername().equals(username) && paramConfig.getPassword().equals(password)) {
            StpUtil.login(10001);
            SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
            return new RetResult().setResult(tokenInfo);
        }
        return new RetResult(CodeEnum.NO_USER_INFO).setResult("登录失败");
    }

    @ApiOperation(value = "登出")
    @PostMapping("/logout")
    public RetResult logout(String username) {
        StpUtil.logout(10001);
        return new RetResult();
    }

}
